import { _decorator, Component, Node } from 'cc';
import { AdComponent } from '../AdComponent';
import *as cc from "cc";
import DatasSpace from '../Tool/DatasSpace';
import { AudioMgr, ENUM_CLIP } from '../Tool/AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('LevelPassChanllge')
export class LevelPassChanllge extends Component {

  @property(Node)
  viewNode: Node = null;


  btnClose() {
    this.btnCloseSetting();
  }

  start() {
    DatasSpace.Instance.gamePause = true;
    // AdComponent.Instance.show5X5CustomAd();
    AdComponent.Instance.showInterstitialFullShow();
    AdComponent.Instance.showBannerAd();
    // tween(this.viewNode).to(0.3, { position:v3(this.viewNode.getPosition().x,-50,0), scale:v3(1.2,0.8,0)}, { easing: 'smooth' }).to(0.3, { position: v3(0,0,0), scale:v3(1,1,0) }, { easing: 'backInOut' }).to(0.3, { scale:v3(1.1,0.9,0)}, { easing: 'backInOut' }).to(0.1, { scale:v3(1,1,0) }, { easing: 'backInOut' }).call(() => {
    // }).start();
  }

  protected onDestroy(): void {
    DatasSpace.Instance.gamePause = false;
    AdComponent.Instance.hideBannerAd();
  }

  btnCloseSetting() {
    AudioMgr.Instance.play(ENUM_CLIP.Click);

    // AdComponent.Instance.instance.playAudio(2);
    // AdComponent.Instance.hide5X5customAd();
    cc.tween(this.viewNode).to(0.5, { position: cc.v3(0, this.viewNode.getPosition().y + 1600, 0) }, { easing: 'backInOut' }).call(() => {
      this.node.removeFromParent();
      this.node.destroy();
      cc.director.loadScene('Home');
    }).start();
  }

  /**
   * @fn 双倍领取每日挑战成功奖励
   * @time 2024 5 29 16:03
   */
  btnGetDailyChanllgeSuccessDoubleReward() {
    AdComponent.Instance.loadVideoAd(0, (res) => {
      if (res) {
        console.log('广告领取成功');
        this.getDailyChanllgeReward(2);
      }
    });

  }

  /**
   * @fn 领取每日挑战成功奖励
   * @time 2024 5 29 16:04
   */
  btnGetReward() {
    this.getDailyChanllgeReward(1);
  }

  /**
   * @fn 每日挑战奖励
   * @time  2024 5 29 16:05
   */
  getDailyChanllgeReward(mult) {
    DatasSpace.Instance.goldNum += 200 * mult;
    DatasSpace.Instance.starNum += 200 * mult;
    DatasSpace.Instance.setGoldNum();
    this.btnCloseSetting();
  }


}


